import request from "@/utils/request";

const baseURL = "/users";

// 用户登录
export const login = (userForm) =>
  request({ url: `${baseURL}/login`, method: "POST", data: userForm });

// 查询用户信息
export const getInfo = () =>
  request({ url: `${baseURL}/userInfo`, method: "GET" });

// 退出登录
export const logout = () =>
  request({ url: `${baseURL}/logout`, method: "POST" });

// 分页查询用户接口
export const getAllUserByPage = ({
  pageNo,
  pageSize,
  account,
  roleId,
  status,
}) =>
  request({
    url: `${baseURL}?pageNo=${pageNo}&pageSize=${pageSize}&account=${account}&roleId=${roleId}&status=${status}`,
    method: "GET",
  });

// 修改用户状态
export const updateUserStatusById = (id, status) =>
  request({
    url: `${baseURL}/${id}/${status}`,
    method: "PUT",
  });

// 批量删除用户
export const deleteUserByIds = (ids) =>
  request({
    url: `${baseURL}/${ids}`,
    method: "DELETE",
  });

// 删除单个用户
export const deleteUserById = (id) =>
  request({
    url: `${baseURL}/one/${id}`,
    method: "DELETE",
  });

// 添加用户
export const addUser = (user) =>
  request({
    url: `${baseURL}`,
    method: "POST",
    data: user,
  });

// 根据用户id获取用户信息
export const getUserInfoById = (id) =>
  request({
    url: `${baseURL}/${id}`,
    method: "GET",
  });

// 更新用户
export const updataUser = (user) =>
  request({
    url: `${baseURL}`,
    method: "PUT",
    data: user,
  });

// 批量添加用户
export const batchInsertUser = (FormData) =>
  request({
    url: `/user/file/upload`,
    method: "POST",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: FormData,
  });

// 上传头像
export const uploadImg = (formData) =>
  request({
    url: `/user/file/image`,
    method: "POST",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: formData,
  });

// 更新用户密码
export const updatePassword = (user) =>
  request({
    url: `${baseURL}/password`,
    method: "POST",
    data: user,
  });

// 管理员重置用户密码
export const resetUserPassword = (userId) =>
  request({
    url: `${baseURL}/reset-password/${userId}`,
    method: "PUT",
  });

export const getTeacherById = (deptId) =>
  request({
    url: `${baseURL}/teacher/${deptId}`,
    method: "GET",
  });
